﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ReferenceScheduler.ConferenceModule;

namespace ReferenceScheduler.Strategy
{
    class TrackScheduler
    {
        List<Talk> talkList;
        List<Session> sessionList;


        public TrackScheduler()
        {
            InitTalkList();
            sessionList = new List<Session>();
        }

        public void InitTalkList()
        {
            string[] lines = System.IO.File.ReadAllLines(@"C:\Users\FUJITSU\Desktop\Talks.txt");
            talkList = new List<Talk>();
            talkList.Add(new Talk("dummy", 0));
            for (int i = 0; i < lines.Length; i++)
            {
                string line = lines[i];
                int lastSpace = line.LastIndexOf(" ");
                string title = line.Substring(0, lastSpace).Trim();
                int interval;
                try{
                    interval  = Int32.Parse(line.Substring(lastSpace + 1).Replace("min", ""));
                }catch(Exception ex)
                {
                    interval = 5;
                }
                talkList.Add(new Talk(title, interval));             
            }
        }

        public void CreateSession()
        { 
            while(talkList.Count > 0 )
            {
                if (talkList.Count == 1 && talkList[0].GetInterval() == 0)
                    return;

                Session newSession = GetNextSession();
                SessionScheduler sessionScheduler = new SessionScheduler(newSession.GetInterval(),talkList);
                sessionScheduler.SelectTalk();
                newSession.SetTalkList(sessionScheduler.GetChosenTalks());
                sessionList.Add(newSession);
                talkList = sessionScheduler.GetReturnedTalks();
            }
        }


        public Session GetNextSession()
        {
            return new Session("Morning",180);
        }

        public string ToString()
        {   
            string myString = "";
            for (int i = 0; i < sessionList.Count; i++ )
            {
                myString += sessionList[i].ToString();
            }
            return myString;
        }

    }
}
